package com.business.corp;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.frame.struts.ActionContext;
import com.frame.struts.BaseBean;

public class WorkQueueForm extends BaseBean
{
    private WorkQueueEntity workqueue = new WorkQueueEntity();

    public String updateWorkQueue()
    {
        HttpServletRequest request = ActionContext.getActionContext()
                                                  .getRequest();
        HttpServletResponse response = ActionContext.getActionContext()
                                                    .getResponse();
        String workqueueid = (String) request.getParameter( "workqueueid" );
        int isFinished = Integer.parseInt( request.getParameter( "setIsFinished" ) );
        WorkQueueFactory factory = WorkQueueFactory.getInstance();
        factory.updateWorkQueue( isFinished, Integer.parseInt( workqueueid ) );
        try
        {
            if( isFinished == 1 )
            {
                response.sendRedirect( "corp/workqueuelist_uf.jsp" );
            }
            else
            {
                response.sendRedirect( "corp/workqueuelist.jsp" );
            }

        }
        catch( IOException ex )
        {
            ex.printStackTrace();
        }
        return null;
    }

    public String updateWorkQueueRemark()
    {
        HttpServletRequest request = ActionContext.getActionContext()
                                                  .getRequest();
        HttpServletResponse response = ActionContext.getActionContext()
                                                    .getResponse();
        int workqueueid = Integer.parseInt( request.getParameter( "workqueueid" ) );
        String remark = request.getParameter( "remark" );
        int isFinished = Integer.parseInt( request.getParameter( "isFinished" ) );
        WorkQueueFactory factory = WorkQueueFactory.getInstance();
        factory.updateWorkQueueRemark( workqueueid, remark );
        try
        {
            if( isFinished == 1 )
            {
                response.sendRedirect( "corp/workqueuelist.jsp" );
            }
            else
            {
                response.sendRedirect( "corp/workqueuelist_uf.jsp" );
            }

        }
        catch( IOException ex )
        {
            ex.printStackTrace();
        }
        return null;
    }

    public String deleteWorkQueue()
    {
        HttpServletRequest request = ActionContext.getActionContext()
                                                  .getRequest();
        HttpServletResponse response = ActionContext.getActionContext()
                                                    .getResponse();
        String workqueueid = (String) request.getParameter( "workqueueid" );
        int isFinished = Integer.parseInt( request.getParameter( "setIsFinished" ) );
        WorkQueueFactory factory = WorkQueueFactory.getInstance();
        factory.delWorkQueue( Integer.parseInt( workqueueid ) );
        try
        {
            if( isFinished == 1 )
            {
                response.sendRedirect( "corp/workqueuelist_uf.jsp" );
            }
            else
            {
                response.sendRedirect( "corp/workqueuelist.jsp" );
            }

        }
        catch( IOException ex )
        {
            ex.printStackTrace();
        }
        return null;
    }

}
